- job = build.present(current_user: current_user)
- pipeline = job.pipeline
- admin = local_assigns.fetch(:admin, false)
- ref = local_assigns.fetch(:ref, nil)
- commit_sha = local_assigns.fetch(:commit_sha, nil)
- retried = local_assigns.fetch(:retried, false)
- pipeline_link = local_assigns.fetch(:pipeline_link, false)
- stage = local_assigns.fetch(:stage, false)
- allow_retry = local_assigns.fetch(:allow_retry, false)
-# This prevents initializing another Ci::Status object where 'status' is used
- status = job.detailed_status(current_user)

%tr.build.commit{ class: ('retried' if retried) }
  %td.status
    -# Sending 'status' prevents calling the user relation inside the presenter, generating N+1,
    -# see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68743
    = render "ci/status/badge", status: status, title: job.status_title(status)

  %td
    - if can?(current_user, :read_build, job)
      = link_to job.name, project_job_path(job.project, job), class: 'gl-text-blue-600!'
    - else
      %span.gl-text-blue-600!
        = job.name

  %td.branch-commit.gl-text-gray-900
    %span.build-link ##{job.id}

    - if ref
      - if job.ref
        .icon-container.gl-display-inline-block
          = job.tag? ? sprite_icon('label', css_class: 'sprite') : sprite_icon('fork', css_class: 'sprite')
        = link_to job.ref, project_ref_path(job.project, job.ref), class: "ref-name"
      - else
        .light= _('none')
      .icon-container.commit-icon
        = custom_icon("icon_commit")

    - if commit_sha
      = link_to job.short_sha, project_commit_path(job.project, job.sha), class: "commit-sha mr-0"

    - if job.stuck?
      %span.has-tooltip{ title: _('Job is stuck. Check runners.') }
        = sprite_icon('warning', css_class: 'text-warning!')

    - if retried
      %span.has-tooltip{ title: _('Job was retried') }
        = sprite_icon('retry', css_class: 'text-warning')

    .label-container
      - if job.tags.any?
        - job.tags.each do |tag|
          = gl_badge_tag tag, variant: :info, size: :sm
      - if job.try(:trigger_request)
        = gl_badge_tag _('triggered'), variant: :info, size: :sm
      - if job.try(:allow_failure) && !job.success?
        = gl_badge_tag _('allowed to fail'), variant: :warning, size: :sm
      - if job.schedulable?
        = gl_badge_tag s_('DelayedJobs|delayed'), variant: :info, size: :sm
      - elsif job.action?
        = gl_badge_tag _('manual'), variant: :info, size: :sm

  - if pipeline_link
    %td
      = link_to pipeline_path(pipeline) do
        %span.pipeline-id ##{pipeline.id}
      %span by
      - if pipeline.user
        = user_avatar(user: pipeline.user, size: 20)
      - else
        %span.monospace API

  - if admin
    %td
      - if job.project
        = link_to job.project.full_name, admin_project_path(job.project)
    %td
      - if job.try(:runner)
        = runner_link(job.runner)
      - else
        .light= _('none')

  - if stage
    %td
      = job.stage_name

  %td
    - if job.duration
      %p.duration
        = sprite_icon("timer")
        = duration_in_numbers(job.duration)

    - if job.finished_at
      %p.finished-at
        = sprite_icon("calendar")
        %span= time_ago_with_tooltip(job.finished_at)

  %td.coverage
    - if job.try(:coverage)
      #{job.coverage}%

  %td
    .gl-text-right
      .btn-group
        - if can?(current_user, :read_job_artifacts, job) && job.artifacts?
          = link_button_to nil, download_project_job_artifacts_path(job.project, job), rel: 'nofollow', download: '', title: _('Download artifacts'), icon: 'download'
        - if can?(current_user, :update_build, job)
          - if job.active?
            = link_button_to nil, cancel_project_job_path(job.project, job, continue: { to: request.fullpath }), method: :post, title: _('Cancel'), icon: 'cancel'
          - elsif job.scheduled?
            = render Pajamas::ButtonComponent.new(disabled: true, icon: 'planning') do
              %time.js-remaining-time{ datetime: job.scheduled_at.utc.iso8601 }
                = duration_in_numbers(job.execute_in)
            - confirmation_message = s_("DelayedJobs|Are you sure you want to run %{job_name} immediately? This job will run automatically after it's timer finishes.") % { job_name: job.name }
            = link_button_to nil, play_project_job_path(job.project, job, return_to: request.original_url),
              method: :post,
              title: s_('DelayedJobs|Start now'),
              class: 'has-tooltip',
              data: { confirm: confirmation_message },
              icon: 'play'
            = link_button_to nil, unschedule_project_job_path(job.project, job, return_to: request.original_url),
              method: :post,
              title: s_('DelayedJobs|Unschedule'),
              class: 'has-tooltip',
              icon: 'time-out'
          - elsif allow_retry
            - if job.playable? && !admin && can?(current_user, :update_build, job)
              = link_button_to nil, play_project_job_path(job.project, job, return_to: request.original_url), method: :post, title: _('Play'), icon: 'play'
            - elsif job.retryable?
              = link_button_to nil, retry_project_job_path(job.project, job, return_to: request.original_url), method: :post, title: _('Retry'), icon: 'retry'
